package org.zfes.snowier.xyz.analysis.analysers.demos;

import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;
import org.zfes.snowier.common.chains.ademo.DemoH1;
import org.zfes.snowier.common.chains.ademo.DemoH2;
import org.zfes.snowier.common.chains.ademo.DemoH3;
import org.zfes.snowier.common.chains.handler.DefaultChainConfig;
import org.zfes.snowier.common.chains.handler.IChainConfig;
import org.zfes.snowier.common.chains.session.BizSession;
import org.zfes.snowier.common.chains.session.ISession;
import org.zfes.snowier.common.eventpub.SimpleSubcriber;
import org.zfes.snowier.xyz.analysis.queue.AnalyQueueBucket;
@Component
public class DataHandlerEntry   implements InitializingBean{
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	

	@Override
	public void afterPropertiesSet() throws Exception {
		logger.info("--doRegist{}");
		
		doRegist() ;
		IChainConfig chainConfig=DefaultChainConfig.init("key").errorContinue(false)
			//	.addLast("DemoHandler1", new DemoHandler1())
				.addLast("DemoHandler2", new DemoHandler2())
				.addLast("DemoHandler3", new DemoHandler3());
		
		logger.info("--chainConfig：{}",chainConfig);
	}
	
	void doRegist() {
		SimpleSubcriber.newIns().regist(AnalyQueueBucket.defaultTopic,val->{
			logger.info("-SimpleSubcriber-val:{}",val);
			//analysisFilterChain.doFilter(instanceKey, data, chain);
			ISession session = BizSession.buid("key").fireStart(val);
			
//			try {
//				TimeUnit.MILLISECONDS.sleep(500);
//			} catch (InterruptedException e1) {
//				e1.printStackTrace();
//			}
		},e->{
			logger.error("custom handler error："+e.getException());
		});
	}
	
}
